/* Name : Main.c * Purpose : Source code for LCD Interfacing with ATMEGA16. * Author : GEMICATES * Date : 10-07-2017 * Website : www.gemicates.org * Revision : None */ #include<avr/io.h> // Header File for ATMEGA16 #include<util/delay.h> // Include Delay Function #define LCD PORTD // To Set Port D as LCD'S DATA I/P Purpose #define CNT PORTA // To Set Port A as LCD'S Command Purpose #define RS PA0 // To Set Port A Pin 0 as Register select pin #define RW PA1 // To Set Port A Pin 1 as Read write pin #define EN PA2 // To Set Port A Pin 2 as Enable pin /* SUBROUTINE FUNCTIONS */ // FUNCTION TO SEND LCD COMMAND void lcd_cmd(unsigned char cmd) { LCD=cmd; CNT=(0<<RS); CNT=(0<<RW); CNT=(1<<EN); _delay_ms(1); CNT=(0<<RS); CNT=(0<<RW); CNT=(0<<EN); _delay_ms(50); return; } // FUNCTION TO SEND LCD DATA void lcd_data(unsigned char data) { LCD=data; CNT=(1<<RS); CNT=(0<<RW); CNT=(1<<EN); _delay_ms(1); CNT=(1<<RS); CNT=(0<<RW); CNT=(0<<EN); _delay_ms(50); return; } // FUCTION TO PRINT STRING void lcd_string(unsigned char *str) { int i; while(str[i] != '\0') { lcd_data(str[i]); i++; } } /* MAIN FUNCTION */ void main() { DDRD=0xff; // To Set Port A as Output DDRA=0x07; // To Set Port A as Output lcd_cmd(0x38); // For using 8-bit 2 row mode and 5x7 Dots of LCD _delay_ms(1); lcd_cmd(0x0e); // Turn display ON for cursor blinking _delay_ms(1); lcd_cmd(0x0c); // Display On cursor Off _delay_ms(1); lcd_cmd(0x01); // Clear screen _delay_ms(1); _delay_ms(50); lcd_cmd(0x87); // Bring cursor to position 7 of ROW 1 lcd_data('H'); // Print Char lcd_data('I'); // Print Char lcd_data('!'); // Print Char lcd_cmd(0xc4); // Bring cursor to position 4 of ROW 2 lcd_string("**GUYS**"); // Print String _delay_ms(1000); lcd_cmd(0x01); // Clear screen _delay_ms(1); lcd_cmd(0x83); // Bring cursor to position 3 of ROW 1 lcd_string("WELCOME TO");// Print String _delay_ms(500); lcd_cmd(0xC4); // Bring cursor to position 4 of ROW 2 lcd_string("GEMICATES"); // Print String _delay_ms(1000); while(1) { lcd_cmd(0x80); // Bring cursor to position 0 of ROW 1 lcd_string("PROGRESS THROUGH"); lcd_cmd(0x1C); // Shift entire display left lcd_cmd(0xC3); // Bring cursor to position 3 of ROW 2 lcd_string("INNOVATION"); lcd_cmd(0x18); // Shift entire display right } }